import {UserMgr}    from '../UserMgr';
import {ReplayMgr}  from '../ReplayMgr';
import {HTTP}       from '../HTTP';
import {Global}     from '../Global';
import {Net}        from '../Net';
import {GameNetMgr} from '../GameNetMgr';
import {AnysdkMgr}  from '../AnysdkMgr';
import {VoiceMgr}   from '../VoiceMgr';
import {AudioMgr}   from '../AudioMgr';
import {Utils}      from '../Utils';
import urlParse     from './urlParse';


export function initMgr(){

    cc.vv = <cc.vv>{};
    cc.vv.game_event_map = {
        GAME_DINGQUE: 'game_dingque',
        GAME_DINGQUE_NOTIFY: 'game_dingque_notify',
        GAME_DINGQUE_FINISH: 'game_dingque_finish',
        PENG_NOTIFY: 'peng_notify',
        GANG_NOTIFY: 'gang_notify',
        GAME_BEGIN: 'game_begin',
        NEW_USER: 'new_user',
        USER_STATE_CHANGED: 'user_state_changed',
        GAME_NUM: 'game_num',
        GAME_HUANPAI: 'game_huanpai',
        HUANPAI_NOTIFY: 'huanpai_notify',
        GAME_HUANPAI_OVER: 'game_huanpai_over',
        VOICE_MSG: 'voice_msg',
        CHAT_PUSH: 'chat_push',
        QUICK_CHAT_PUSH: 'quick_chat_push',
        EMOJI_PUSH: 'emoji_push',
        GAME_CHUPAI: 'game_chupai',
        GAME_END: 'game_end',
        QUICK_CHAT: 'quick_chat',
        EMOJI: 'emoji',
        CHAT: 'chat',
        GAME_SYNC: 'game_sync',
        GAME_CHUPAI_NOTIFY: 'game_chupai_notify',
        GUO_NOTIFY: 'guo_notify',
        GAME_MOPAI: 'game_mopai',
        HUPAI: 'hupai',
        HANGANG_NOTIFY: 'hangang_notify',
        DISSOLVE_AGREE: 'dissolve_agree',
        LOGIN: 'login',
        DISSOLVE_REJECT: 'dissolve_reject',
        DISSOLVE_REQUEST: 'dissolve_request',
        DISSOLVE_NOTICE: 'dissolve_notice',
        DISSOLVE_CANCEL: 'dissolve_cancel',
        HUANPAI: 'huanpai',
        MJ_CLICKED: 'mj_clicked',
        DISCONNECT: 'disconnect',
        LOGIN_FINISHED: 'login_finished',
        CHUPAI: 'chupai',
        GAME_HOLDS: 'game_holds',
        CHECK_IP: 'check_ip',
        GAME_ACTION: 'game_action',
        MJ_COUNT: 'mj_count',
        GUO_RESULT: 'guo_result',
        LOGIN_RESULT: 'login_result',
        GAME_OVER: 'game_over',
        PENG: 'peng',
        GANG: 'gang',
        HU: 'hu',
        GUO: 'guo',
        PUSH_NOTICE: 'push_notice',
        DISPRESS: 'dispress',
        EXIT: 'exit',
        EXIT_RESULT: 'exit_result',
        EXIT_NOTIFY_PUSH: 'exit_notify_push',
        USER_STATE_PUSH: 'user_state_push',
        USER_READY_PUSH: 'user_ready_push',
        GAME_HOLDS_PUSH: 'game_holds_push',
        GAME_BEGIN_PUSH: 'game_begin_push',
        GAME_PLAYING_PUSH: 'game_playing_push',
        GAME_PLAYING: 'game_playing',
        GAME_SYNC_PUSH: 'game_synv_push',
        GAME_DINGQUE_PUSH: 'game_dingque_push',
        GAME_HUANPAI_PUSH: 'game_huanpai_push',
        HANGANG_NOTIFY_PUSH: 'hangang_notify_push',
        GAME_ACTION_PUSH: 'game_action_push',
        GAME_CHUPAI_PUSH: 'game_chupai_push',
        GAME_NUM_PUSH: 'game_num_push',
        GAME_OVER_PUSH: 'game_over_push',
        MJ_COUNT_PUSH: 'mj_count_push',
        HU_PUSH: 'hu_push',
        GAME_CHUPAI_NOTIFY_PUSH: 'game_chupai_notify_push',
        GAME_MOPAI_PUSH: 'game_mopai_push',
        GUO_NOTIFY_PUSH: 'guo_notify_push',
        GUOHU_PUSH: 'guohu_push',
        GAME_HUANPAI_OVER_PUSH: 'game_huanpai_over_push',
        PENG_NOTIFY_PUSH: 'peng_notify_push',
        GANG_NOTIFY_PUSH: 'gang_notify_push',
        GAME_DINGQUE_NOTIFY_PUSH: 'game_dingque_notify_push',
        GAME_DINGQUE_FINISH_PUSH: 'game_dingque_finish_push',
        DISSOLVE_NOTICE_PUSH: 'dissolve_notice_push',
        DISSOLVE_CANCEL_PUSH: 'dissolve_cancel_push',
        VOICE_MSG_PUSH: 'voice_msg_push',
        READY: 'ready',
        NEW_USER_COMES_PUSH: 'new_user_comes_push',
        DINGQUE: 'dingque',
        DISPRESS_PUSH: 'dispress_push',
        GAME_PING: 'game_ping',
        GAME_PONG: 'game_pong',
    };

    cc.vv.userMgr = new UserMgr();
    cc.vv.replayMgr = new ReplayMgr();
    cc.vv.http = HTTP;
    cc.vv.global = Global;
    cc.vv.net = Net;
    cc.vv.gameNetMgr = new GameNetMgr();
    cc.vv.gameNetMgr.initHandlers();
    // cc.vv.anysdkMgr = new AnysdkMgr();
    // cc.vv.anysdkMgr.init();
    // cc.vv.voiceMgr = new VoiceMgr();
    // cc.vv.voiceMgr.init();
    cc.vv.audioMgr = new AudioMgr();
    cc.vv.audioMgr.init();
    cc.vv.utils = new Utils();
    cc.args = urlParse();
    cc.vv.logStyle = 'background: green; color: red; font-size: 50px;';
    

    cc.vv.debugToTextArr = function debugToTextArr(arr: number[]){
        if(!arr){
            return;
        }
        let tempArr = [];
        for (let i = 0; i < arr.length; i++) {
            tempArr[i] = arr[i];
        }

        tempArr.sort((a, b) => {
            return a - b;
        });

        for (let i = 0; i < tempArr.length; i++) {
            let n = '';
            let t = tempArr[i] % 9 + 1;
            if (tempArr[i] < 9) {
                n = '筒';
            }
            else if (tempArr[i] < 18) {
                n = '条';
            }
            else {
                n = '万';
            }
            tempArr[i] = t + n;
        }
        return tempArr;
    }

    cc.vv.debugToText = function debugToText(mjId) {
        let n = '';
        let x = mjId % 9 + 1;
        if (mjId < 9) {
            n = '筒';
        }
        else if (mjId < 18) {
            n = '条';
        }
        else {
            n = '万';
        }
        return x + n;
    }


    cc.vv.debug = true;
}